package com.yumaolin.deepunderstand.leetcode.algorithm.medium;

public class MaxProfit2 {
    public static int maxProfit(int[] prices) {
        int len = prices.length;
        if(len < 2){
            return 0;
        }
        int res = 0;
        for(int i=1;i<len;i++){
            int diff = prices[i] - prices[i-1];
            if(diff > 0){
                res += diff;
            }
        }
        return res;
    }

    public static void main(String[] args) {
        int[] prices = new int[]{7,1,5,3,6,4};
        System.out.println(maxProfit(prices));
    }
}
